package com.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletSecurityElement;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.util.FileUtil;

public class FileUpLoadAction extends ActionSupport {
	private File multiFile;
	private String multiFileFileName;
	private String multiFileContentType;

	public File getMultiFile() {
		return multiFile;
	}
	public void setMultiFile(File multiFile) {
		this.multiFile = multiFile;
	}
	public String getMultiFileFileName() {
		return multiFileFileName;
	}
	public void setMultiFileFileName(String multiFileFileName) {
		this.multiFileFileName = multiFileFileName;
	}
	
	public String getMultiFileContentType() {
		return multiFileContentType;
	}
	public void setMultiFileContentType(String multiFileContentType) {
		this.multiFileContentType = multiFileContentType;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String fileUploadInit(){
		return "success";
	}
	public String UploadInit(){
		return "init";
	}
	public String fileUploadStart() throws IOException{
		HttpServletResponse reponse=ServletActionContext.getResponse();	
		PrintWriter out=reponse.getWriter();
		File newfile=this.getMultiFile();
		String filename=this.getMultiFileFileName();
    //将文件放于项目部署路径下的upload文件夹下
		String path="F:/FileUpload/"+ filename;
	//根据相对部署路径计算完整路径
		//path=ServletActionContext.getServletContext().getRealPath(path);
		//将临时文件复制到上述路径下
		FileUtil.copy(newfile, new File(path));
		out.print("{'msg':'"+filename+"'}");
		return null;
	}
}
